<template>
  <div class="app-container">
    <div class="charts-container">
      <div style="width: 50%; margin-top: 50px; display: inline-block;">
        <div id="bie" style="width: 100%; height: 400px;"></div>
      </div>

      <div style="width: 50%; margin-top: 50px; display: inline-block;">
        <div id="bar" style="width: 100%; height: 400px;"></div>
      </div>
    </div>

    <div style="width: 100%; margin-top: 50px;">
      <div id="line" style="width: 100%; height: 400px;"></div>
    </div>
  </div>
</template>


<script>
import * as echarts from "echarts";
import request from "@/utils/request";

export default {
  name: "Analysis",
  data() {

  },
  mounted() {
    this.initEcharts();
  },
  methods: {
    initEcharts() {
      //渲染饼图数据
      request.get("/orders/orders/echarts/bie").then(res => {
        if (res.code === 200) {
          this.initBie(res.data)
        } else {
          this.$message.error(res.msg);
        }
      })
      //渲染柱状图数据
      request.get("/reservation/reservation/echarts/bar").then(res => {
        if (res.code === 200) {
          let map = res.data;
          this.initBar(map.xAxis, map.yAxis)
        } else {
          this.$message.error(res.msg);
        }
      })
      //渲染折线图数据
      request.get("/reservation/reservation/echarts/line").then(res => {
        if (res.code === 200) {
          let map = res.data;
          this.initLine(map.xAxis, map.yAxis)
        } else {
          this.$message.error(res.msg);
        }
      })
    },

    initBie(data) {
      let chartDom = document.getElementById('bie');
      let myChart = echarts.init(chartDom);
      let option;
      option = {
        title: {
          text: '理疗订单统计',
          subtext: '统计维度：理疗名称',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [
          {
            name: '理疗名称',
            type: 'pie',
            radius: '50%',
            data: data,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };
      option && myChart.setOption(option);
    },

    initBar(xAxis, yAxis) {
      let chartDom = document.getElementById('bar');
      let myChart = echarts.init(chartDom);
      let option;
      option = {
        title: {
          text: '预约医师统计',
          left: 'center'
        },
        xAxis: {
          type: 'category',
          data: xAxis
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: yAxis,
            type: 'bar',
            showBackground: true,
            backgroundStyle: {
              color: 'rgba(180, 180, 180, 0.2)'
            }
          }
        ]
      };
      option && myChart.setOption(option);
    },

    initLine(xAxis, yAxis) {
      let chartDom = document.getElementById('line');
      let myChart = echarts.init(chartDom);
      let option;
      option = {
        title: {
          text: '预约人次统计',
          left: 'center'
        },
        xAxis: {
          type: 'category',
          data: xAxis
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: yAxis,
            type: 'line'
          }
        ]
      };
      option && myChart.setOption(option);
    },

  },
};
</script>
